<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <button>添加列表</button>
    <ul>
        <li>香蕉</li>
        <li>苹果</li>
        <li>鸭梨</li>
    </ul>
    <script>
        let ul = document.querySelector("ul");
        let btn = document.querySelector("button");
        let inp = document.querySelector("input");
        btn.onclick = function(){
            let value = inp.value;
            let li = document.createElement("li");
            let txt = document.createTextNode(value);
            ul.appendChild(li);
            li.appendChild(txt);
        }
        let list = document.querySelectorAll("li");
        for(let i in list){
            list[i].onclick = function(){
                ul.removeChild(this)
            }
        }
    </script>
</body>
</html>